﻿using System.Diagnostics;
using System.Windows;
using System.Windows.Input;

namespace TestApp
{

    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            this.DataContext = new Window1ViewModel();


            // 注册命令绑定
            CommandBindings.Add(new CommandBinding(
                AppCommands.SaveDocument,
                ExecuteSaveDocument,
                CanExecuteSaveDocument));
        }

        // 使用传统事件方式更新文本框内容
        private void OnEventButtonClick(object sender, RoutedEventArgs e)
        {
            EventTextBox.Text = "事件：通过 Click 事件更新内容";

        }

        private void ExecuteSaveDocument(object sender, ExecutedRoutedEventArgs e)
        {
            MessageBox.Show("Test save。。。。。");
        }

        private void CanExecuteSaveDocument(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        /// <summary>
        /// Bubbling 冒泡事件	从子控件 → 父控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Click 事件处理器执行");

        }



        /// <summary>
        /// 向下传递  隧道事件 从根节点 → 子控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            Debug.WriteLine("PreviewMouseDown");
            //e.Handled = true;  //事件被提前拦截并标记为已处理（e.Handled = true）了，导致冒泡事件不再触发
            base.OnPreviewMouseDown(e);
        }
        private void Grid_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {

        }

        /// <summary>
        /// 向上传递 冒泡事件 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            Debug.WriteLine("MouseDown");
        }
        /// <summary>
        /// Direct	直达事件	不传播
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }
    }
}
